package com.jingan.nursinghome.regulatory.dialog.micrometertable;

import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.jingan.nursinghome.regulatory.R;
import com.jingan.nursinghome.regulatory.adapter.PageAdapter;
import com.jingan.nursinghome.regulatory.data.MicrometerTable;
import com.jingan.nursinghome.regulatory.view.MyActionBar;
import com.jingan.nursinghome.regulatory.view.MyTextView;

import cn.android.support.v7.lib.sin.crown.base.BaseActivity;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/17.
 */

public class XuantiDialog extends BaseDialog {
    private XuantiDialog(BaseActivity baseActivity) {
        init(baseActivity, R.layout.dialog_micrometertablleos_xuanti, false);
        window.setWindowAnimations(cn.android.support.v7.lib.sin.crown.R.style.crown_window_right);
        initUI();
        //adapterUI();
    }

    public static XuantiDialog xuantiDialog;

    public static BaseListenner<Integer> mBaseListenner;

    public static XuantiDialog getInstance(BaseActivity baseActivity, BaseListenner<Integer> baseListenner) {
        mBaseListenner = baseListenner;
        if (isfinish(baseActivity,xuantiDialog)) {
            xuantiDialog = new XuantiDialog(baseActivity);
        }
        return xuantiDialog;
    }

    MyActionBar myActionBar;
    MyTextView mytextview;
    RecyclerView recyclerView;

    public void initUI() {
        myActionBar = (MyActionBar) findViewById(R.id.MyActionBar);
        myActionBar = (MyActionBar) findViewById(R.id.MyActionBar);
        myActionBar.setLeftBimapAndTitle(null, "千分评分系统");
        myActionBar.setBaseListennerLeft(new BaseListenner() {
            @Override
            public void onResult(Object result) {
                dismiss();
            }
        });
        mytextview = (MyTextView) findViewById(R.id.mytextview);

        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(baseActivity, 5);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
                super.getItemOffsets(outRect, itemPosition, parent);
                outRect.left = ProportionUtils.getInstance().adapterInt(18);
                outRect.right = outRect.left;
                outRect.bottom = ProportionUtils.getInstance().adapterInt(21);
                if(itemPosition<=4){
                    outRect.top=outRect.bottom;
                }
            }

            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
//                outRect.left = ProportionUtils.getInstance().adapterInt(18);
//                outRect.right = outRect.left;
//                outRect.bottom = ProportionUtils.getInstance().adapterInt(21);

//                int postion = parent.getChildAdapterPosition(view);
//                if (postion <= 4) {
//                    outRect.top = ProportionUtils.getInstance().adapterInt(60);
//                }
//                if (postion % 5 == 0) {
//                    outRect.left = ProportionUtils.getInstance().adapterInt(30);
//                }
//                if ((postion + 1) / 5 == 0) {
//                    outRect.right = ProportionUtils.getInstance().adapterInt(30);
//                }
            }
        });
//        recyclerView.setAdapter(new PageAdapter(MicrometerTable.getInstance().getTopics(CreateMicrometerTableDailog.rid,CreateMicrometerTableDailog
//                .jlyName).size(), MicrometerTableOSDialog.count, MicrometerTableOSDialog.getMaxPage()));
    }

    public void adapterUI() {
        ProportionUtils.getInstance().adapterScreen(baseActivity, findViewById(R.id.dialog_micrometertableos_constraintLayout));
        ProportionUtils.getInstance().adapterView(findViewById(R.id.bg_bottom));
        ProportionUtils.getInstance().adapterView(findViewById(R.id.view_line));
    }

    @Override
    protected void listener() {
        MicrometerTable.getInstance().getTopicinfoList().size();
        mytextview.setIndexAndMax(MicrometerTableOSDialog.pageIndex + "",MicrometerTable.getInstance().getTopicinfoList().size() + "");
//        recyclerView.getAdapter().notifyDataSetChanged();
        recyclerView.setAdapter(new PageAdapter(MicrometerTable.getInstance().getTopicinfoList().size(), MicrometerTableOSDialog.count, MicrometerTableOSDialog.getMaxPage()));
    }

    @Override
    protected void recycleView() {

    }
}
